<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2018/4/14
  Time: 13:53
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>官网管理</title>
    <link href="${pageContext.request.contextPath}/static/css/bootstrap.min.css" rel="stylesheet">
    <link href="${pageContext.request.contextPath}/static/css/plugins/bootstrap-table/bootstrap-table.min.css"
          rel="stylesheet">
    <link href="${pageContext.request.contextPath}/static/css/font-awesome.min93e3.css" rel="stylesheet">
    <link href="${pageContext.request.contextPath}/static/css/style.min.css?v=4.1.0" rel="stylesheet">
</head>
<body class="gray-bg">

<div class="wrapper wrapper-content animated fadeInRight">
    <table id="webtable"></table>
</div>


<script src="${pageContext.request.contextPath}/static/js/jquery.min.js"></script>
<script src="${pageContext.request.contextPath}/static/js/bootstrap.min.js"></script>
<script src="${pageContext.request.contextPath}/static/js/content.min.js?v=1.0.0"></script>
<script src="${pageContext.request.contextPath}/static/js/plugins/bootstrap-table/bootstrap-table.js"></script>
<script src="${pageContext.request.contextPath}/static/js/plugins/bootstrap-table/bootstrap-table-mobile.js"></script>
<script src="${pageContext.request.contextPath}/static/js/plugins/bootstrap-table/locale/bootstrap-table-zh-CN.min.js"></script>
<script src="${pageContext.request.contextPath}/static/layer/layer.js"></script>


<script>
    var $wtable = $("#webtable");

    $wtable.bootstrapTable({
        url: '/online',
        method: 'get',
        striped: true,
        cache: false,
        height: 670,
        pagination: true,
        sidePagination: "client",
        pageNumber: 1,
        pageSize: 15,
        pageList: [],
        search: true,
        searchTimeOut: 500,
        trimOnSearch: true,
        uniqueId: 'id',
        queryParams: function (params) { // 请求服务器数据时发送的参数，可以在这里添加额外的查询参数，返回false则终止请求

        },
        responseHandler: function (json) {
            return json.data;
        },
        columns: [{
            title: '管理列表名称',
            field: 'title'
        }, {
            title: '最近修改时间',
            field: 'utime',
            formatter: function (value) {
                if (!value) {
                    return "-";
                } else {
                    var crtTime = new Date(parseInt(value) * 1000);
                    return timeformat("yyyy-MM-dd hh:mm:ss", crtTime);
                }
            }
        }, {
            title: '操作',
            formatter: function (value,row) {
                return '<button class=\'btn btn-primary\' onclick="onlineEdit('+row.id+')">编辑</button>';
            }
        }, {
            field: 'id',
            visible: false
        }
        ]
    });

    //格式化时间
    function timeformat(fmt, date) {
        var o = {
            "M+": date.getMonth() + 1,                 //月份
            "d+": date.getDate(),                    //日
            "h+": date.getHours(),                   //小时
            "m+": date.getMinutes(),                 //分
            "s+": date.getSeconds(),                 //秒
            "S": date.getMilliseconds()             //毫秒
        };
        if (/(y+)/.test(fmt))
            fmt = fmt.replace(RegExp.$1, (date.getFullYear() + "").substr(4 - RegExp.$1.length));
        for (var k in o)
            if (new RegExp("(" + k + ")").test(fmt))
                fmt = fmt.replace(RegExp.$1, (RegExp.$1.length === 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
        return fmt;
    }
    //编辑
    function onlineEdit(id) {
        var value = $wtable.bootstrapTable('getRowByUniqueId', id);
        layer.open({
            type: 2,
            title: '编辑列表',
            area: ['800px', '90%'],
            fixed: false,
            maxmin: true,
            shadeClose: true,
            content: "/page/webmanage/edit_online.jsp",
            success:function (layero, index) {
                var iframeWin = window[layero.find('iframe')[0]['name']];
                var body = layer.getChildFrame('body',index);
                iframeWin.con(value.content);
                body.find("input[name='id']").val(value.id)
            }
        });
    }


</script>

</body>
</html>
